#include <bits/stdc++.h>
using namespace std;

int t,n,a[200005],clr[200005];

int main()
{
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	cin >> t;
	while(t--)
	{
		long long ans = 0;
		cin >> n;
		for(int i = 1;i <= n;i++)
			cin >> a[i];
		for(int i = 0;i < (1 << n);i++)
		{
			int t1 = i,pos = 0;
			while(t1)
			{
				clr[++pos] = t1 % 2;
				t1 >>= 1;
			}
			long long sum = 0;
			for(int i = 2;i <= n;i++)
			{
				for(int j = i - 1;j >= 1;j--)
				{
					if(clr[i] == clr[j])
					{
						if(a[i] == a[j])
							sum += a[i];
						break;
					}
				}
			}
			ans = max(ans,sum);
		}
		cout << ans << endl;
	}
	return 0;
}